package com.kayang.webapi.tool;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class FileUploadConfig {
	 public String SaveTo ;

     public String FilePath ;

     public Boolean ZipCompress ;

     public String ZipPassword ;

     public String UserName ;

     public String Password ;

     public String SaveType ;
     
     public String Port ;


	public String getPort() {
		return Port;
	}



	public void setPort(String port) {
		Port = port;
	}



	@SuppressWarnings({ "unchecked", "rawtypes" })
	public FileUploadConfig(String fConfigXml) throws DocumentException
     {
 		SAXReader saxReader = new SAXReader();
 		  Document document;
 		 Element root = null;
 		    try {
 	            document = saxReader.read(new ByteArrayInputStream(fConfigXml.getBytes()));
 	            root = document.getRootElement();
 	        } catch (DocumentException e) {
 	            e.printStackTrace();
 	        }
 		    
		Map<String ,String> map=new HashMap();
		 for (Iterator iterator = root.elementIterator(); iterator.hasNext();) { 
	            Element e = (Element) iterator.next(); 
	            map.put(e.getName(), e.getText()); 
	        } 
 		
 		
 		
        /* var query = from item in rssXDoc.Element("FileUpload").Elements()
                     select new
                     {
                         TypeName = item.Name,
                         TextVal = item.Value,
                     };*/
         Set<String> keys = map.keySet();
         for (String objTypeName  : keys)
         {
             if (objTypeName.toUpperCase().toUpperCase().equals("SAVETO"))
             {
                 this.SaveTo =map.get(objTypeName);
             }
             else if (objTypeName.toUpperCase().equals("FILEPATH"))
             {
                 this.FilePath = map.get(objTypeName);
             }
             else if (objTypeName.toUpperCase().equals("ZIPCOMPRESS"))
             {
                 this.ZipCompress =Converter.toBoolean(map.get(objTypeName));
             }
             else if (objTypeName.toUpperCase() .equals("ZIPPASSWORD"))
             {
                 this.ZipPassword = map.get(objTypeName);
             }
             else if (objTypeName.toUpperCase().equals("USERNAME"))
             {
                 this.UserName = map.get(objTypeName);
             }
             else if (objTypeName.toUpperCase() .equals("PASSWORD"))
             {
                 this.Password = map.get(objTypeName);
             }
         }
     }
     
     

	public FileUploadConfig() {
	}



	public String getSaveTo() {
		return SaveTo;
	}

	public void setSaveTo(String saveTo) {
		SaveTo = saveTo;
	}

	public String getFilePath() {
		return FilePath;
	}

	public void setFilePath(String filePath) {
		FilePath = filePath;
	}

	public Boolean getZipCompress() {
		return ZipCompress;
	}

	public void setZipCompress(Boolean zipCompress) {
		ZipCompress = zipCompress;
	}

	public String getZipPassword() {
		return ZipPassword;
	}

	public void setZipPassword(String zipPassword) {
		ZipPassword = zipPassword;
	}

	public String getUserName() {
		return UserName;
	}

	public void setUserName(String userName) {
		UserName = userName;
	}

	public String getPassword() {
		return Password;
	}

	public void setPassword(String password) {
		Password = password;
	}

	public String getSaveType() {
		return SaveType;
	}
	
	public void setSaveType(String saveType) {
		SaveType = saveType;
	}

}
